home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.0 / stk-3 / blt-for-STk-3.0 / blt-1.9 / src / bltUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-16  |  7.6 KB  |  250 lines

  1. /*
  2.  * bltUtil.c --
  3.  *
  4.  *    This module implements utility procedures for the BLT
  5.  *    toolkit.
  6.  *
  7.  * Copyright 1993-1994 by AT&T Bell Laboratories.
  8.  * Permission to use, copy, modify, and distribute this software
  9.  * and its documentation for any purpose and without fee is hereby
  10.  * granted, provided that the above copyright notice appear in all
  11.  * copies and that both that the copyright notice and warranty
  12.  * disclaimer appear in supporting documentation, and that the
  13.  * names of AT&T Bell Laboratories any of their entities not be used
  14.  * in advertising or publicity pertaining to distribution of the
  15.  * software without specific, written prior permission.
  16.  *
  17.  * AT&T disclaims all warranties with regard to this software, including
  18.  * all implied warranties of merchantability and fitness.  In no event
  19.  * shall AT&T be liable for any special, indirect or consequential
  20.  * damages or any damages whatsoever resulting from loss of use, data
  21.  * or profits, whether in an action of contract, negligence or other
  22.  * tortuous action, arising out of or in connection with the use or
  23.  * performance of this software.
  24.  *
  25.  */
  26.  
  27. #include "blt.h"
  28.  
  29.  
  30. /*
  31.  *----------------------------------------------------------------------
  32.  *
  33.  * Blt_FindCmd --
  34.  *
  35.  *      Given the name of a command, return a pointer to the
  36.  *      clientData field of the command.
  37.  *
  38.  * Results:
  39.  *      A standard TCL result. If the command is found, TCL_OK
  40.  *    is returned and clientDataPtr points to the clientData
  41.  *    field of the command (if the clientDataPtr in not NULL).
  42.  *
  43.  * Side effects:
  44.  *      If the command is found, clientDataPtr is set to the address
  45.  *    of the clientData of the command.  If not found, an error
  46.  *    message is left in interp->result.
  47.  *
  48.  *----------------------------------------------------------------------
  49.  */
  50.  
  51. int
  52. Blt_FindCmd(interp, cmdName, clientDataPtr)
  53.     Tcl_Interp *interp;        /* Interpreter in which to look. */
  54.     char *cmdName;        /* Name of desired command */
  55.     ClientData *clientDataPtr;
  56. {
  57.     Tcl_CmdInfo info;
  58.  
  59.     if (!Tcl_GetCommandInfo(interp, cmdName, &info)) {
  60.     return TCL_ERROR;
  61.     }
  62.     if (clientDataPtr != NULL) {
  63.     *clientDataPtr = info.clientData;
  64.     }
  65.     return TCL_OK;
  66. }
  67.  
  68. /*
  69.  *----------------------------------------------------------------------
  70.  *
  71.  * Blt_OptionChanged --
  72.  *
  73.  *      Given the specs and option argument names (terminated by a NULL),
  74.  *    search  a Tk_ConfigSpec structure for any matching specs which
  75.  *      has been reset.
  76.  *
  77.  * Results:
  78.  *      Returns 1 if one of the options has changed, 0 otherwise.
  79.  *
  80.  *----------------------------------------------------------------------
  81.  */
  82.  
  83. int
  84. Blt_OptionChanged(specs, opt0, opt1, opt2, opt3, opt4, opt5, opt6, opt7,
  85.     opt8, opt9, opt10)
  86.     Tk_ConfigSpec *specs;
  87.     char *opt0, *opt1, *opt2, *opt3, *opt4, *opt5, *opt6, *opt7, *opt8;
  88.     char *opt9, *opt10;
  89. {
  90.     register Tk_ConfigSpec *specPtr;
  91.     char *argv[12];
  92.     register char **argPtr;
  93.  
  94.     argv[0] = opt0;
  95.     argv[1] = opt1;
  96.     argv[2] = opt2;
  97.     argv[3] = opt3;
  98.     argv[4] = opt4;
  99.     argv[5] = opt5;
  100.     argv[6] = opt6;
  101.     argv[7] = opt7;
  102.     argv[8] = opt8;
  103.     argv[9] = opt9;
  104.     argv[10] = opt10;
  105.     argv[11] = NULL;
  106.     for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
  107.     for (argPtr = argv; *argPtr != NULL; argPtr++) {
  108.         if ((Tcl_StringMatch(specPtr->argvName, *argPtr)) &&
  109.         (specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)) {
  110.         return 1;
  111.         }
  112.     }
  113.     }
  114.     return 0;
  115. }
  116.  
  117. #ifndef HAVE_STRDUP
  118. /*
  119.  *----------------------------------------------------------------------
  120.  *
  121.  * strdup --
  122.  *
  123.  *      Create a copy of the string from heap storage.
  124.  *
  125.  * Results:
  126.  *      Returns a pointer to the need string copy.
  127.  *
  128.  *----------------------------------------------------------------------
  129.  */
  130. char *
  131. strdup(string)
  132.     char *string;
  133. {
  134.     char *newPtr;
  135.  
  136.     newPtr = (char *)malloc(sizeof(char) * (strlen(string) + 1));
  137.     strcpy(newPtr, string);
  138.     return (newPtr);
  139. }
  140.  
  141. #endif /*HAVE_STRDUP*/
  142.  
  143. #ifndef HAVE_STRCASECMP
  144.  
  145. static unsigned char lcase[] =
  146. {
  147.     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  148.     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  149.     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  150.     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  151.     '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  152.     '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  153.     '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  154.     '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  155.     '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  156.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  157.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  158.     '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  159.     '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  160.     '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  161.     '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  162.     '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  163.     '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  164.     '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  165.     '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  166.     '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  167.     '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  168.     '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  169.     '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  170.     '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  171.     '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  172.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  173.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  174.     '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  175.     '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  176.     '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  177.     '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  178.     '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  179. };
  180.  
  181. /*
  182.  *----------------------------------------------------------------------
  183.  *
  184.  * strcasecmp --
  185.  *
  186.  *      Compare two strings, disregarding case.
  187.  *
  188.  * Results:
  189.  *      Returns the following:
  190.  *
  191.  *    zero      - two strings are equal
  192.  *    negative  - first string is less than second
  193.  *    positive  - first string is greater than second
  194.  *
  195.  *----------------------------------------------------------------------
  196.  */
  197. int
  198. strcasecmp(str1, str2)
  199.     CONST char *str1;
  200.     CONST char *str2;
  201. {
  202.     register unsigned char *s = (unsigned char *)str1;
  203.     register unsigned char *t = (unsigned char *)str2;
  204.  
  205.     for ( /* empty */ ; (lcase[*s] == lcase[*t]); s++, t++) {
  206.     if (*s == '\0') {
  207.         return 0;
  208.     }
  209.     }
  210.     return (lcase[*s] - lcase[*t]);
  211. }
  212.  
  213. /*
  214.  *----------------------------------------------------------------------
  215.  *
  216.  * strncasecmp --
  217.  *
  218.  *      Compare two strings, disregarding case, up to a given length.
  219.  *
  220.  * Results:
  221.  *      Returns the following:
  222.  *
  223.  *    zero      - two strings are equal
  224.  *    negative  - first string is less than second
  225.  *    positive  - first string is greater than second
  226.  *
  227.  *----------------------------------------------------------------------
  228.  */
  229. int
  230. strncasecmp(str1, str2, length)
  231.     CONST char *str1;
  232.     CONST char *str2;
  233.     size_t length;
  234. {
  235.     register unsigned char *s = (unsigned char *)str1;
  236.     register unsigned char *t = (unsigned char *)str2;
  237.  
  238.     for ( /* empty */ ; (length > 0); s++, t++, length--) {
  239.     if (lcase[*s] != lcase[*t]) {
  240.         return (lcase[*s] - lcase[*t]);
  241.     }
  242.     if (*s == '\0') {
  243.         return 0;
  244.     }
  245.     }
  246.     return 0;
  247. }
  248.  
  249. #endif /*HAVE_STRCASECMP*/
  250.